var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("BoxItem"),
    l = t("AdView"),
    d = cc._decorator,
    u = d.ccclass,
    h =
        (d.property,
        d.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.selSkillItem = 1;
                e.tag = "UIZhuanBei";
                e.wearObj = {};
                e.looperNode = [];
                return e;
            }
            e.prototype.onShowEnd = function () {
                AdView.showAd(function () {
                    console.log("打开装备，展示插屏");
                }, l.AdTypeEm.equip);
                EVUIEffView.on(EVUIEffView.updateSkillTaskItem, this.updateView.bind(this), this);
                EVUIEffView.on(EVUIEffView.clickBoxItem, this.clickItem.bind(this), this);
                EVUIEffView.on(EVUIEffView.checkCostUI, this.updateView.bind(this), this);
                this.updateView();
                QAudio.play(QAudio.ui_popup);
                GameDataValue.closeAllEquip();
                if (!GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][3])) {
                    GuildCache.checkKey = GuildCache.oncecheckId[2][3];
                    GuildCache.overOnceGuid(GuildCache.oncecheckId[2][3]);
                    GuildCache.openGuildView();
                }
            };
            e.prototype.onCloseStart = function () {
                QAudio.play(QAudio.ui_button);
                EVUIEffView.offTarget(this);
                for (var t = 0; t < this.looperNode.length; t++) QLooperNode.putNode(this.looperNode[t]);
                for (var e in this.wearObj) this.wearObj[e] && QLooperNode.putNode(this.wearObj[e].node);
                CacheDataManager.updateCostDataView = !0;
            };
            e.prototype.clickItem = function (t, e, o, a) {
                e == this.tag && c.default.open(s.UIID.UIWearCom, {id: o, typeIndex: a || this.selSkillItem});
            };
            e.prototype.checkWearData = function () {
                for (var t = GameDataValue.getAllSelfEquip(), e = {}, o = {}, a = 0; a < 3; a++) {
                    e[(c = a + 1)] = 0;
                    o[c] = !1;
                }
                var i = CacheDataManager.getCostumeup(),
                    n = CacheDataManager.getCostume();
                for (var r in t) e[(s = n[(d = i[t[r].id]).costume_id]).type] = Math.max(e[s.type], d.quality);
                for (var r in t) {
                    var s;
                    e[(s = n[(d = i[t[r].id]).costume_id]).type] = Math.max(e[s.type], d.quality);
                }
                for (a = 0; a < 3; a++) {
                    var c = a + 1 + "",
                        p = GameDataValue.getWearEquip(c),
                        l = GameDataValue.getEquipData(p);
                    if (l) {
                        var d = i[l.id];
                        e[c] > d.quality && (o[c] = !0);
                    } else o[c] = e[c] >= 1;
                }
                var u = !1;
                for (a = 0; a < 3; a++) {
                    this["_tab" + (c = a + 1)].redCom1.active = o[c];
                    o[c] && (u = !0);
                }
                u ? GameDataValue.setHaveCanWear(!0) : GameDataValue.setHaveCanWear(!1);
                for (a = 0; a < 3; a++) this.checkWearType(a + 1);
            };
            e.prototype.checkWearType = function (t) {
                var e = GameDataValue.getWearEquip(t + "");
                if (e) {
                    if (this.wearObj[t]) {
                        this.wearObj[t].id = e;
                        this.viewItem(this.wearObj[t].node, GameDataValue.getEquipData(e), t, t, !1, null, 0, 0);
                    } else {
                        var o = this["_viewCurNode" + t];
                        if (o) {
                            var a = QLooperNode.getNode(QLooperNode.tag_boxItem);
                            a.parent = o;
                            a.setPosition(cc.Vec2.ZERO);
                            this.viewItem(a, GameDataValue.getEquipData(e), t, t, !1, null, 0, 0);
                            this.wearObj[t] = {id: e, node: a};
                        }
                    }
                } else if (this.wearObj[t]) {
                    QLooperNode.putNode(this.wearObj[t].node);
                    this.wearObj[t] = null;
                }
            };
            e.prototype.checkTypeRed = function () {};
            e.prototype._onTab1TouchEnd = function () {
                this.selSkillItem = 1;
                this.updateView();
            };
            e.prototype._onTab2TouchEnd = function () {
                this.selSkillItem = 2;
                this.updateView();
            };
            e.prototype._onTab3TouchEnd = function () {
                this.selSkillItem = 3;
                this.updateView();
            };
            e.prototype._onOpenMergeTouchEnd = function () {
                c.default.open(s.UIID.UIMerge);
                this.closeUI();
            };
            e.prototype.updateTabView = function () {
                for (var t = 1; t <= 3; t++) this.setNodeSpriteView(this["_tab" + t], t == this.selSkillItem);
            };
            e.prototype.setNodeSpriteView = function (t, e) {
                SpriteView.setTaBgSpriteView(t.bg, t.view, e);
            };
            e.prototype.updateView = function () {
                var t = CacheDataManager.getTypeEquip(this.selSkillItem);
                this.updateLevelData(t);
                this.updateTabView();
                this.checkWearData();
                this._addLab.$Label.string = CacheDataManager.getLabAllAdd() + "%";
                if (
                    !GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][6]) &&
                    GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][5])
                ) {
                    GuildCache.overOnceGuid(GuildCache.oncecheckId[2][6]);
                    this.scheduleOnce(function () {
                        GuildCache.checkKey = GuildCache.oncecheckId[2][6];
                        GuildCache.openGuildView();
                    }, 0.1);
                }
            };
            e.prototype.updateLevelData = function (t) {
                if (t.length > 0) {
                    for (var e = t, o = e.length; o < this.looperNode.length; o++) this.looperNode[o].active = !1;
                    var a = GameDataValue.getWearEquip(this.selSkillItem + ""),
                        i = GameDataValue.getEquipData(a),
                        n = 1,
                        r = CacheDataManager.getCostumeup(),
                        s = 1,
                        c = {};
                    for (o = 0; o < e.length; o++) n = Math.max(n, r[e[o].id].quality);
                    for (o = 0; o < e.length; o++) {
                        if (!this.looperNode[o]) {
                            var l = QLooperNode.getNode(QLooperNode.tag_boxItem);
                            l.setPosition(cc.Vec2.ZERO);
                            l.parent = this._allContent;
                            this.looperNode.push(l);
                        }
                        var d = r[e[o].id].costume_id;
                        if (!c[d]) {
                            c[d] = s;
                            s++;
                        }
                        this.viewItem(this.looperNode[o], e[o], o, this.selSkillItem, !0, i, n, c[d]);
                    }
                    var u = this.getMinListIndex();
                    if (this.looperNode[u]) {
                        var h = this.looperNode[u].getComponent(p.default);
                        if (h) {
                            h.openRed();
                            h.node.zIndex -= 1;
                        }
                    }
                } else for (o = 0; o < this.looperNode.length; o++) this.looperNode[o].active = !1;
            };
            e.prototype.clickFirstItem = function () {
                if (this._allContent.childrenCount > 0) {
                    var t = this._allContent.children[0].getComponent(p.default);
                    t && t.clickItem();
                }
            };
            e.prototype.getMinListIndex = function () {
                for (var t = -1, e = 999, o = 0; o < this.looperNode.length; o++)
                    if (this.looperNode[o] && this.looperNode[o].active && this.looperNode[o].zIndex < e) {
                        var a = this.looperNode[o].getComponent(p.default);
                        if (a && a.wearNode && !a.wearNode.active && a.redTag) {
                            e = this.looperNode[o].zIndex;
                            t = o;
                        }
                    }
                return t;
            };
            e.prototype.viewItem = function (t, e, o, a, i, n, r, s) {
                t.active = !0;
                var c = t.getComponent(p.default);
                if (c) {
                    var l = CacheDataManager.getCostumeup(),
                        d = CacheDataManager.getCostume();
                    if (l[e.id]) {
                        c.id = e.indexId;
                        c.tag = this.tag;
                        c.nodeKindItem.setTypeKind(a, l[e.id].quality);
                        c.typeIndex = a;
                        c.levelLab.string = "lv:" + e.lv;
                        c.resetView();
                        d[l[e.id].costume_id];
                        if (n && n.indexId == e.indexId) {
                            t.zIndex = 0;
                            i && c.openWear();
                        } else {
                            l[e.id].quality >= r &&
                                (n && l[n.id] ? l[n.id].quality < l[e.id].quality && (c.redTag = !0) : (c.redTag = !0));
                            var u = 900 - 20 * l[e.id].quality - s - a;
                            t.zIndex = u;
                        }
                        SpriteView.setTaskSprite(c.iconSprite, CacheDataManager.getEquipCostumeUpToIcon(l[e.id]));
                        c.setQualityData(l[e.id].quality);
                    }
                }
            };
            e.prototype.clickNode = function () {
                CacheDataManager.updateCostDataView = !0;
                this.closeUI();
            };
            e.prototype._onOpenDetailTouchEnd = function () {
                c.default.open(s.UIID.UITipAllEquip);
            };
            return n([u], e);
        })(r.default));
o.default = h;
